﻿using UnityEngine;
using System;
using FibMatrix;

public class AutoDestroy : MonoBehaviour {

	public float lifeTime = 1.0f;

	private float _elapseTime = 0f;

	void Awake()
	{
		ResourceFacade.AddAutoUnloadObject (this.gameObject);
	}

	void Start()
	{
		_elapseTime = Time.realtimeSinceStartup;
	}

	void Update()
	{
		if (Time.realtimeSinceStartup - _elapseTime >= lifeTime)
		{
			ResourceFacade.RemoveAutoUnloadObject (this.gameObject);
			ResourceFacade.instance.Unload (this.gameObject);
		}
	}

}
